<template>
  <div class='content'>
    <div class='title'>
      <div></div>
      <p>用电情况</p>
    </div>

    <div class='btn-wrap'>
      <div :class="[activeClass == 'Today' ? 'active' : '', 'btn']" @click='handleActive("Today")'>今日</div>
      <div :class="[activeClass == 'Month' ? 'active' : '', 'btn']" @click='handleActive("Month")'>本月</div>
      <div :class="[activeClass == 'Year' ? 'active' : '', 'btn']" @click='handleActive("Year")'>本年度</div>
    </div>
    <div class='block'>
      <span>今日用电</span>
      <span>{{ active.now }}</span>
    </div>
    <div class='block'>
      <span>昨日同期</span>
      <span>{{ active.before }}</span>
    </div>
    <div class='block'>
      <span>环比</span>
      <span>{{ active.ratio }}</span>
    </div>
    <div class='block'>
      <span>{{ active.maxTime }}</span>
      <span>最大用电时间</span>
    </div>
    <div class='block'>
      <span>{{ active.maxValue }}</span>
      <span>最大用电量</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Electricity',
  props: ['ele'],
  data: () => {
    return {
      active: {},
      activeClass: 'Today',
    }
  },
  watch: {
    ele: function(newVal, oldVal) {
      this.active = newVal['Today']
    },
  },
  methods: {
    handleActive(value) {
      this.activeClass = value
      this.active = this.ele[value]
    },
  },
}
</script>

<style lang='scss' scoped>
.content {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-top: 1px;

  .btn-wrap {
    width: 100%;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 14px;

    .btn {
      min-width: 90px;
      height: 34px;
      box-sizing: border-box;
      padding: 0 24px;
      margin-right: 15px;
      font-size: 20px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      text-align: center;
      line-height: 34px;
      color: #7988AD;
      cursor: pointer;
    }

    .active {
      background: linear-gradient(90deg, #3494FF, #006DFF);
      box-shadow: 0px 6px 12px 0px rgba(35, 113, 255, 0.29);
      border-radius: 17px;
      color: #FFFFFF;

    }
  }

  .block {
    width: 90%;
    height: 40px;
    margin: 6px auto;
    box-sizing: border-box;
    padding: 0 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    span {
      font-size: 16px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #7988AD;
    }
  }

  .block:hover {
    background: rgba(0, 124, 240, 0.12);
    border-radius: 8px;
  }

  .title {
    width: 90px;
    position: absolute;
    left: 0;
    top: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    div {
      width: 6px;
      height: 30px;
      background: #007CF0;
      border-radius: 2px;
    }

    p {
      font-size: 17px;
      font-family: Source Han Sans CN;
      font-weight: 600;
      color: #222222;
    }
  }
}
</style>
